// Replication: Cassella, Fagan and Theriault (PRQ)
// Contact E.J. Fagan, ejfagan@uic.edu, with questions or for raw data.

// Analysis starts here
use member_level_all.dta, clear

gen biden_margin = (biden_vote - trump_vote) / (biden_vote + trump_vote)
gen competitiveness = abs(biden_margin)
replace competitiveness = 1 - competitiveness
replace class = 1 if class>1
gen nonwhite = 1 - white


drop if zero_earmarks==1


// Table 1: Summary Statistics
sum class young race interest old rural women military lgbt religious farmers any_target rep_target dem_target

// Table 2: Recipient Organization types
sum k12 nonprof faith service

// Tables 3 and 4 below

// Figure 1: Policy Topics

graph hbar (sum) count, over(topicname, sort(1) descending) ytitle("Earmark Requests") ylabel(,nogrid) 

// Table 5: Difference of Means Tests, Targets and Type of Program
// Target

ttest college, by(democrat)
ttest k12, by(democrat)
ttest interest, by(democrat)
ttest religious, by(democrat) 
ttest lgbt, by(democrat)
ttest rural, by(democrat)
ttest military, by(democrat)
ttest farmers, by(democrat)
ttest women, by(democrat)
ttest young, by(democrat)
ttest old, by(democrat)
ttest race, by(democrat)
ttest class, by(democrat)

ttest any_target, by(democrat)
ttest dem_target, by(democrat)
ttest rep_target, by(democrat)

// Program type or location
ttest service, by(democrat)
ttest nonprof, by(democrat)
ttest faith, by(democrat)

// Table 6: Logistic Regression Estimation of Target Populations Mentioned in House Earmark Justification Letters

logit any_target nominate_dim1 if democrat==1, or
logit any_target nominate_dim1 if democrat==0, or 

logit dem_target nominate_dim1 if democrat==1, or 
logit rep_target nominate_dim1 if democrat==0, or 

// Table 7: Logistic Regression Estimation of Target Populations Mentioned in House Earmark Justification Letters, Race and Class

logit race nominate_dim1 nonwhite  if democrat==1, or
logit race nominate_dim1 nonwhite  if democrat==0, or

logit class nominate_dim1 poverty blue_collar if democrat==1, or
logit class nominate_dim1 poverty blue_collar if democrat==0, or



// Table 8: Difference of Means Tests, Policy Topic
tab majortopic, gen(mt)
rename mt1 macroeconomics  
rename mt2 civilrights 
rename mt3 healthcare 
rename mt4 agriculture 
rename mt5 labor 
rename mt6 education 
rename mt7 environment 
rename mt8 energy 
rename mt9 immigration 
rename mt10 transportation 
rename mt11 crime 
rename mt12 socialwelfare
rename mt13 housing
rename mt14	business
rename mt15 defense
rename mt16 science
rename mt17 govops
rename mt18 publiclands

ttest macroeconomics , by(democrat)
ttest civilrights , by(democrat)
ttest healthcare , by(democrat)
ttest agriculture , by(democrat)
ttest labor  , by(democrat)
ttest education , by(democrat)
ttest environment , by(democrat)
ttest energy , by(democrat)
ttest immigration , by(democrat)
ttest transportation , by(democrat)
ttest crime , by(democrat)
ttest socialwelfare , by(democrat)
ttest housing , by(democrat)
ttest business , by(democrat)
ttest business , by(democrat)
ttest defense , by(democrat)
ttest science , by(democrat)
ttest govops , by(democrat)
ttest publiclands , by(democrat)

// Table 9: Logistic Regression Estimation of Whether Earmark Requests are on Owned Issues

logit dem_owned nominate_dim1 if democrat==1 
logit rep_owned nominate_dim1 if democrat==0

// Member level tables

use member_level_all.dta, clear

gen biden_margin = (biden_vote - trump_vote) / (biden_vote + trump_vote)
gen competitiveness = abs(biden_margin)
replace competitiveness = 1 - competitiveness
replace amount_millions = 0 if amount_millions==.
replace count = 0 if zero==1 

//Table 3: Distribution of Earmark Requests by Party

sum amount_millions competitiveness count if democrat==1
sum amount_millions competitiveness count if democrat==0

drop if democrat==1

collapse (mean) competitiveness amount_millions nominate_dim1 zero_earmarks (sum) count, by(bioname)

gen any_earmarks = .
replace any_earmarks = 1 if zero==0
replace any_earmarks = 0 if zero==1

// Table 4: Logistic Regression Estimation of Requesting At Least One Earmark, House Republicans Only

logit any_earmarks nominate_dim1, or
logit any_earmarks competitiveness, or
logit any_earmarks nominate_dim1 competitiveness, or
